package hotel.action;

import hotel.model.IRequest;
import hotel.service.RequestService;
import hotel.service.ServiceManager;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
/**
 * This class get the list of requests from DataBase
 * @author Alex
 *
 */
public class RequestListAction extends Action
{
	private static final Logger logger = Logger.getLogger(RequestListAction.class);
	private static final String REQUESTLISTACTION_ERROR = "Error in RequestListAction:";
	@Override
    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
    throws Exception 
    {
		String mapper = null;//ForwardActionTo.ERROR;
		try
		{
	    	RequestService requestService = ServiceManager.getDefault().getRequestService();
	        List<IRequest> requests = null;
	        requests = requestService.getRequests();
	        request.setAttribute("requests", requests);
	        mapper = ForwardActionTo.SUCCESS;  
		}
		catch(NullPointerException e)
		{
			logger.error(REQUESTLISTACTION_ERROR + e);
		}
		
		return mapping.findForward(mapper);
	}
}
